package com.foreknow.elmboot.mapper;

import com.foreknow.elmboot.po.Cart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper {

    @Select("select * from cart where userId=#{userId} order by cartId")
    public List<Cart> getCartByUserId(String userId);

    @Select("select * from cart where userId=#{userId} and businessId=#{businessId} order by foodId")
    public List<Cart> listCart(String userId,Integer businessId);

    @Insert("insert into cart(foodId,businessId,userId,quantity) values(#{foodId},#{businessId},#{userId},#{quantity})")
    public int saveCart(Integer foodId,Integer businessId,String userId,Integer quantity);

    @Update("update cart set cart.quantity=#{quantity} where cart.foodId=#{foodId} and cart.businessId=#{businessId} and cart.userId=#{userId}")
    public int updateCart(Integer foodId,Integer businessId,String userId,Integer quantity);

    @Delete("delete from cart where cart.foodId=#{foodId} and cart.businessId=#{businessId} and cart.userId=#{userId}")
    public int removeFood(Integer foodId,Integer businessId,String userId);

    @Delete("delete from cart where cart.businessId=#{businessId} and cart.userId=#{userId}")
    public int removeCart(Integer businessId,String userId);
}
